﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace homework_5
{
    class order
    {
        public int ordernum { get; set; }
        public string buyer { get; set; }
        private DateTime time { get; set; }//修改后
        public double sum { get; set; }

        public List<orderdetail> Details { get; } = new List<orderdetail>();


        public order(int num,string buyer,double sum)
        {
            this.ordernum = ordernum;
            this.buyer = buyer;
            time = DateTime.Now;
            this.sum = sum;
        }

        public void AddDetails(orderdetail orderDetail)
        {
            if (this.Details.Contains(orderDetail))
            {
                throw new ApplicationException($"The goods ({orderDetail.ProductName}) exist in order {ordernum}");
            }
            Details.Add(orderDetail);
        }

        public override bool Equals(object obj)
        {
            order m = obj as order;
            return m.ordernum == ordernum;
        }

        public override int GetHashCode()
        {
            return 2108858624 + ordernum.GetHashCode();
        }

        public override string ToString()
        {
            return $"订单号: {ordernum}, 订单价格: {sum}, 客户名称: {buyer}]";
        }

    }
}
